﻿using System;
using System.Collections.Generic;
using System.Linq;
using RanchBuddy.Core.Domain;
using RanchBuddy.Core.Domain.Impl;
using RanchBuddy.Core.Services.Impl;
using StructureMap;

namespace RanchBuddy.Core.DataAccess.Impl
{
    [Pluggable("Default")]
    public class CompanyAccountTypeRepository : ICompanyAccountTypeRepository
    {
        public IRepositoryStatus GetCompanyAccountTypes(int companyTypeID)
        {
            IRepositoryStatus rs = ObjectFactory.GetInstance<IRepositoryStatus>();
            List<CompanyAccountType> result = new List<CompanyAccountType>();
            try
            {
                using (RanchBuddyDataContext dc = ObjectFactory.GetInstance<IConnection>().GetLsContext())
                {
                    result =
                        dc.CompanyAccountTypes.OrderBy(t => t.Name).Where(t => t.CompanyTypeID == companyTypeID).ToList();
                }
                rs.StatusType = Status.StatusTypes.Success;
                rs.SetObject(result);
            }
            catch (Exception e)
            {
                rs.StatusType = Status.StatusTypes.Failure;
                rs.AddMessage(e.Message + " " + e.StackTrace);
            }
            return rs;
        }
    }
}
